package com.hig.risk.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hig.risk.domain.RiskHazardSource;
import com.hig.risk.service.IRiskHazardSourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 危险源管理Controller
 * 
 * @author scp
 * @date 2024-09-25
 */
@RestController
@RequestMapping("/risk/source")
public class RiskHazardSourceController extends BaseController
{
    @Autowired
    private IRiskHazardSourceService riskHazardSourceService;

    /**
     * 查询危险源管理列表
     */
    @PreAuthorize("@ss.hasPermi('risk:source:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskHazardSource riskHazardSource)
    {
        startPage();
        List<RiskHazardSource> list = riskHazardSourceService.selectRiskHazardSourceList(riskHazardSource);
        return getDataTable(list);
    }

    /**
     * 导出危险源管理列表
     */
    @PreAuthorize("@ss.hasPermi('risk:source:export')")
    @Log(title = "危险源管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RiskHazardSource riskHazardSource)
    {
        List<RiskHazardSource> list = riskHazardSourceService.selectRiskHazardSourceList(riskHazardSource);
        ExcelUtil<RiskHazardSource> util = new ExcelUtil<RiskHazardSource>(RiskHazardSource.class);
        return util.exportExcel(list, "危险源管理数据");
    }

    /**
     * 获取危险源管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('risk:source:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskHazardSourceService.selectRiskHazardSourceById(id));
    }

    /**
     * 新增危险源管理
     */
    @PreAuthorize("@ss.hasPermi('risk:source:add')")
    @Log(title = "危险源管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskHazardSource riskHazardSource)
    {
        return toAjax(riskHazardSourceService.insertRiskHazardSource(riskHazardSource));
    }

    /**
     * 修改危险源管理
     */
    @PreAuthorize("@ss.hasPermi('risk:source:edit')")
    @Log(title = "危险源管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskHazardSource riskHazardSource)
    {
        return toAjax(riskHazardSourceService.updateRiskHazardSource(riskHazardSource));
    }

    /**
     * 删除危险源管理
     */
    @PreAuthorize("@ss.hasPermi('risk:source:remove')")
    @Log(title = "危险源管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskHazardSourceService.deleteRiskHazardSourceByIds(ids));
    }

    @GetMapping("/optionselect")
    public AjaxResult optionselect()
    {
        RiskHazardSource riskHazardSource = new RiskHazardSource();
        List<RiskHazardSource> list = riskHazardSourceService.selectSourceAll(riskHazardSource);
        return AjaxResult.success(list);
    }

    @Log(title = "危险源管理", businessType = BusinessType.UPDATE)
    @PutMapping("/check/{ids}")
    public AjaxResult check(@PathVariable Long[] ids)
    {
        return toAjax(riskHazardSourceService.checkRiskHazardSource(ids));
    }
    @GetMapping("/overtime")
    public AjaxResult overtime()
    {
        RiskHazardSource riskHazardSource = new RiskHazardSource();
        return riskHazardSourceService.selectOvertime(riskHazardSource);
    }
}
